package com.gopay.common.security.SensitiveInfo.dao.impl;

import java.io.Serializable;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.gopay.common.base.dao.impl.BaseDAOImpl;
import com.gopay.common.domain.sensitiveInfo.CipheredDictionary;
import com.gopay.common.security.SensitiveInfo.dao.CipheredDictionaryDao;

/**
 * 
 * @ClassName: CipheredDictionaryDaoImpl 
 * @Description: 敏感信息字典表dao实现类 
 * @author zyt 
 * @date 2017年1月5日 下午5:06:36
 */
@Repository("cipheredDictionaryDao")
public class CipheredDictionaryDaoImpl extends 
	BaseDAOImpl<CipheredDictionary, Serializable> implements CipheredDictionaryDao {

	/**
	 * 
	 * @Description: 		根据密文查找对应的字典信息是否存在 
	 * @param cipherContext	密文
	 * @return 				存在，则返回对应字典信息，否则返回null
	 * @author zyt
	 */
	private CipheredDictionary getCardDicByCipherContext(String cipherContext) {
		String hql = "from CipheredDictionary c where c.cipherContext = '" + cipherContext + "'";
		List<CipheredDictionary> cipherDictionaryList = this.findByHql(hql);
		if(cipherDictionaryList == null || cipherDictionaryList.size() <= 0) {
            return null;
        }
		return cipherDictionaryList.get(0);
	}

	@Override
	public void insertIfNotExsit(CipheredDictionary cDictionary) {
		if(getCardDicByCipherContext(cDictionary.getCipherContext()) == null){
			this.save(cDictionary);
		}
	}


}
